{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "## 加载html模板\n",
    "\n",
    "class MainHandler(web.RequestHandler):\n",
    "    def initialize(self, db):\n",
    "        self.db = db\n",
    "\n",
    "    async def get(self, *args, **kwargs):\n",
    "        message_from = MessageForm()\n",
    "        self.render(\"message.html\", message_form=message_from)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "## 模板内容\n",
    "\n",
    "\n",
    "<!DOCTYPE html>\n",
    "<html lang=\"en\">\n",
    "<head>\n",
    "    <meta charset=\"UTF-8\">\n",
    "    <title></title>\n",
    "    <link rel=\"stylesheet\" type=\"text/css\" href=\"{{ static_url('style.css') }}\">\n",
    "</head>\n",
    "<body>\n",
    "<form action=\"/\" method=\"post\" class=\"smart-green\">\n",
    "    <h1>留言信息\n",
    "        <span>请留下你的信息.</span>\n",
    "    </h1>\n",
    "    <!--<input id=\"id\" type=\"hidden\" name=\"id\" value=\"{{ id }}\" />-->\n",
    "    <!--  关闭转义  -->\n",
    "    {% autoescape None %}\n",
    "    {% for field in message_form %}\n",
    "        <span>{{ field.label.text }} :</span>\n",
    "        {{ field(placeholder=\"请输入\"+field.label.text) }}\n",
    "\n",
    "        {% if field.errors %}\n",
    "            {% for error_msg in field.errors %}\n",
    "                <div class=\"error-msg\">{{ error_msg }}</div>\n",
    "            {% end %}\n",
    "            {% else %}\n",
    "                <div class=\"error-msg\"></div>\n",
    "        {% end %}\n",
    "    {% end %}\n",
    "    <label>\n",
    "        <span>&nbsp;</span>\n",
    "        <input type=\"submit\" class=\"button\" value=\"提交\"/>\n",
    "    </label>\n",
    "</form>\n",
    "\n",
    "</body>\n",
    "</html>"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
